﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __12AA7E65_AEFD_4cea_A04D_C40F49D8A4D9__
#define __12AA7E65_AEFD_4cea_A04D_C40F49D8A4D9__

namespace xos_log
{
    class log_file : public i_log_file
    {
    public:
        typedef xos_stl::auto_list< xos_box::i_buf > LOG_LIST;
        typedef LOG_LIST::iterator LOG_ITER;
        typedef xos::release_impl< log_file > T;

    public:
        log_file();
        ~log_file();

    protected:
        std::string m_full_file;
        std::string m_path;

        LOG_LIST m_log_list;

        int m_nBufNumToFlush;
        int m_nYear;
        int m_nMonth;
        int m_nDay;
        int m_nCurHour;
        int m_nCurMinute;

    public:
        int set_log_file_path( const char * lpszLogPath );
        int set_buf_num_to_flush( int nBufNum );
        int out_put_log( i_log_msg * pLogMsg );
        int flush();

    protected:
        int add_log_to_buf( i_log_msg * pLogMsg );
        int create_log_path();
        int fmt_file_name();

    public:
        int put_back_to_pool( log_file * pT, bool bLock );
        int init();
        int term();
    };
} // xos_log

#endif // __12AA7E65_AEFD_4cea_A04D_C40F49D8A4D9__
